<?php
/**
 * @link https://ym2.cleverstone.top
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

/** @var \yii\web\View $this */
/** @var \builder\form_step\FormStepBuilder $context 当前分步表单组件实例 */
/** @var array $stepItem 分步项 */
/** @var array $rootLayout 根布局 */
/** @var array $footerBtn 尾部按钮 */

// 上下文对象
$context = $this->context;
// 总步数
$countStep = count($stepItem);
?>
<div ng-controller="ym2.ctrl.<?= $context->id ?>" class="ym2-form-step-ui card border-0 <?= $rootLayout['class'] ?>" style="<?= $rootLayout['style'] ?>"<?= $rootLayout['attribute'] ?>>
    <div class="card-header bg-white border-0 px-5">
        <div class="step-header d-flex align-items-center justify-content-center">
            <?php foreach ($stepItem as $index => $item): ?>

            <div class="{{ currentPageIndex == <?= $index ?> ? 'item-checked' : '' }} header-item d-flex align-items-center {{ currentPageIndex >= <?= $index ?> ? 'text-primary' : 'text-muted' }} cursor-pointer flex-shrink-0">
                <span class="{{ currentPageIndex > <?= $index ?> ? '<?= $context->stepOkIcon ?>' : ( currentPageIndex === <?= $index ?> ? '<?= $context->stepIconActiveMap[$index] ?>' : '<?= $context->stepIconMap[$index] ?>' ) }} layui-font-28 item-icon"></span>
                <span class="item-title f16 pl-2"><?= $item['title'] ?></span>
            </div>
            <?php if ($index + 1 < $countStep):?>

            <hr class="flex-grow-1 mx-2 {{ currentPageIndex > <?= $index ?> ? 'border-bottom-primary' : 'border-bottom' }}"/>
            <?php endif; ?>
            <?php endforeach; ?>

        </div>
    </div>
    <?php foreach ($stepItem as $index => $item): ?>

    <div ng-show="currentPageIndex === <?= $index ?>">
        <?= $item['content'] ?>

        <div class="card-header bg-white border-0 clearfix px-5">
            <div class="text-left pull-left">
                <?php if ($index > 0): ?>

                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" ng-click="actionPrevStep(<?= $index ?>)">上一步</button>
                <?php endif; ?>
            </div>
            <div class="text-right pull-right">
                <?php if ($index + 1 < $countStep): ?>

                <button type="button" class="layui-btn layui-btn-sm layui-btn-theme" ng-click="actionNextStep(<?= $index ?>, '<?= $item["callId"] ?>')">下一步</button>
                <?php endif; ?>
                <?php if ($index + 1 >= $countStep && !empty($footerBtn['submit'])): ?>

                <button type="button" class="layui-btn layui-btn-sm layui-btn-theme" ng-click="actionSubmit('<?= $item["callId"] ?>')">
                    <?= $footerBtn['submit']['title'] ?>
                </button>
                <?php endif; ?>
                <?php foreach ($footerBtn as $type => $value): ?>
                <?php switch ((string)$type): case 'close': //关闭按钮 ?>

                <button type="button" class="layui-btn layui-btn-sm layui-btn-gray ym2-form-close-ui" ng-click="actionClose()"><?= $value['title'] ?></button>
                <?php break; case 'back': //返回按钮 ?>

                <button type="button" class="layui-btn layui-btn-sm layui-btn-gray ym2-form-back-ui" ng-click="actionBack()"><?= $value['title'] ?></button>
                <?php break; default: //额外的按钮 ?>

                <div class="d-inline-block" ng-if="currentPageIndex === <?= $index ?>">
                    <?= $value['content'] ?>
                </div>
                <?php endswitch; ?>
                <?php endforeach; ?>

            </div>
        </div>
    </div>
    <?php endforeach; ?>

</div>
